<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
    <title></title>
    <link rel="stylesheet" href="./css/base.css"/>
    <link rel="stylesheet" href="./css/taocan-zhifu.css"/>
</head>
<body>

<div class="warp">
    <header class="clearfix">
        <a href="#" class="back fl" onclick="backall()"></a>
        提交订单
    </header>
    <div class="main">
        <div class="server_box">
            <ul>
                <li><strong class="server_p">套餐名称</strong><span id="PackageName">套餐·套餐名称</span></li>
                <li><strong class="technical ">套餐价格</strong><span id="price">团队： 25800元/26人</span></li>
            </ul>
        </div>
        <div class="relation">
            <ul>
                <li><label for="user" class="user">联系姓名<input type="text" placeholder="请输入您的姓名" id="user"/></label></li>
                <li><label for="photo" class="photo">联系电话<input type="number" placeholder="请输入您的联系电话" id="photo" onblur="checkphone()"/></label></li>
                <li><label for="address" class="address">服务地址<input type="text" placeholder="请输入您的服务地址" id="address"/></label></li>
                <li><label for="remark" class="remark">备注信息<input type="text" placeholder="用户的需要或疑问，包括其他情况备注便于服务前的准备" id="remark"/></label></li>
            </ul>

        </div>
        <div class="pay">
            <ul>
                <li><strong class="server_p">支付金额</strong><span id="priceone">2380.3</span></li>

            </ul>
        </div>

    </div>
    <footer>
        <div class="answers">
            <button onclick=" topay()" id="btn">预约支付</button>
        </div>

    </footer>
</div>
<script src="./js/base.js"></script>
<script src="./js/jquery-1.12.4.js"></script>
<script src="./js/zhifu.js"></script>
<script src="./lib/layer/layer.js"></script>
<!--<script src="./js/taocan-zhifu.js"></script>-->
<script>
    function checkphone() {
        var phone = $("#photo").val();
        var reg = '^(1)[0-9]{10}$';
        var flag = phone.match(reg);
        if (!flag) {
            layer.open({
                content: "手机号码格式错误，请重新确认",
                btn: ['确定',]
            });
            return;
        }
    }
    function backall() {
        window.history.back();
    }
    var Request = new Object();
    var url=window.location.search;
    var serviceId;
    var tianshu;
     function topay() {
         var sessionid=sessionStorage['sessionId'];
         var name=$("#user").val();
         if(name==null||name.trim()==""){
             layer.open({
                 content: "请填写姓名",
                 btn: ['确定',]
             });
             return;
         }
         var phone=$("#photo").val();
         if(phone==null||phone.trim()==""){
             layer.open({
                 content: "请填写手机号",
                 btn: ['确定',]
             });
             return;
         }
         var address=$("#address").val();
         if(address==null||address.trim()==""){
             layer.open({
                 content: "请填写地址",
                 btn: ['确定',]
             });
             return;
         }
         var price=$("#priceone").text();
         var quntity=tianshu;
         var serviceid=serviceId;
         var memo=$("#remark").val();
         var data={sessionid:sessionid,name:name,phone:phone,address:address,amount:price,quntity:quntity,serviceId:serviceid,memo:memo,type:0};
         $.ajax({
            type:"POST",
            url:baseURL+"yuesao/order/saveOrder",
            data:data,
            dataType:"json",
            success:function (r) {
                console.log(r)
                if(r.code=="USR124"){
                    layer.open({
                        content: r.msg
                        , btn: ['确定',],
                        skin: 'my-skin'
                        , yes: function (index) {
                            layer.close(index);
                            window.location.href="login.html";
                        }
                    });
                }else if(r.code=="USR100"){
//                    layer.open({
//                        content: r.msg,
//                        btn: ['确定',]
//                    });
                }else if(r.code=="USR103"){
                    layer.open({
                        content:"您有未支付订单，请先支付"
                        , btn: ['确定',],
                        skin: 'my-skin'
                        , yes: function (index) {
                            layer.close(index);
                            window.location.href="zhifu-dingdan.html";
                        }
                    });
                }else if(r.code=="USR138 "){
//                    layer.open({
//                        content: r.msg,
//                        btn: ['确定',]
//                    });
                }else if(r.code=="USR201"){
//                    layer.open({
//                        content: r.msg,
//                        btn: ['确定',]
//                    });
                }else if(r.code=="USR000"){
//                	window.location.href=baseURL+"pay/create?orderId="+r.data+"&returnUrl=http://ys.stevengg.com/yuesao_h5/one.html";
                	var orderNumber=r.data;
                    payMethod(orderNumber,"one.html","zhifu-dingdan.html");
                }
            }
        })


   }
$(function () {
    if(url.indexOf("?")!=-1) {
        var str = url.substr(1)　//去掉?号
        var　strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            Request[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
        }
    }
    $("#PackageName").html(Request["PackageName"]);
    $("#price").html(Request["price"]+"元/"+Request["days"]+"天");
    var price=$("#price").text();
    tianshu=Request["days"];
    serviceId=Request["id"];
    $("#priceone").html(Request["price"]);

})
//    function onBridgeReady(data){
//         console.log("进入支付方法");
//         console.log(data);
//        WeixinJSBridge.invoke(
//            'getBrandWCPayRequest', {
//                "appId":data.appId,     //公众号名称，由商户传入
//                "timeStamp":data.timeStamp,         //时间戳，自1970年以来的秒数
//                "nonceStr":data.nonceStr, //随机串
//                "package":data.package,
//                "signType":data.signType,         //微信签名方式：
//                "paySign":data.paySign //微信签名
//            },
//            function(res){
//                if(res.err_msg == "get_brand_wcpay_request:ok" ) {
//                    window.location.href="one.html";
//// 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
//                }else{
//                    alert(res.err_msg);
//                }
//            }
//        );
//    }

</script>
</body>

</html>